//
//  UIImage+Extension.h
//  Demo04_裁切
//
//  Created by 孟瑞瑞 on 15/9/22.
//  Copyright (c) 2018年 CSDN. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "NSData+ImageFormat.h"

typedef UIImage JPEGImage;
typedef UIImage PNGImage;
typedef NSData JPEGData;
typedef NSData PNGData;

typedef NS_ENUM(NSUInteger, WaterMarkPosition) {
    WaterMarkPositionLeftTop,
    WaterMarkPositionRightTop,
    WaterMarkPositionLeftBottom,
    WaterMarkPositionRightBottom,
    WaterMarkPositionCenter
};

/// <#Description#>
@interface UIImage (Extension)

+(instancetype)imageWithName:(NSString *)name border:(CGFloat)border borderColor:(UIColor *)color;
+(instancetype)imageWithCaptureView:(UIView *)view;
//获得某个范围内的屏幕图像
+ (UIImage *)imageFromView:(UIView *)theView  atFrame:(CGRect)r;
/// 截屏
+ (UIImage *)screenshot;

+ (UIImage *)imageWithRoundCorner:(UIImage *)sourceImage cornerRadius:(CGFloat)cornerRadius size:(CGSize)size;

/**
 *  根据图片url获取图片尺寸
 */
+ (CGSize)getImageSizeWithURL:(id)URL;
// 根据图片url获取图片尺寸
+ (CGSize)getImageSizeWithImageURL:(id)imageURL;

#pragma mark -按照你想要的比例去缩放图片
- (UIImage *)scaleToWidth:(CGFloat)width;
- (UIImage *)clipToHeight:(CGFloat)height;
-(UIImage*)getSubImage:(CGRect)rect;

+(UIImage *)reduceImage:(UIImage *)image percent:(float)percent;

+(UIImage *)scaleToSize:(UIImage *)aImage size:(CGSize)size;

-(UIImage *)imageCompressForWidth:(UIImage *)sourceImage targetWidth:(CGFloat)defineWidth;

+(UIImage *)oldImage:(UIImage *)oldImage toSize:(CGSize)size;

+(UIImage *)scaleImage:(UIImage *)image toKb:(NSInteger)kb;

-(NSData *)compressWithMaxLength:(NSUInteger)maxLength;

+(UIImage *)imageWithRadius:(CGFloat)radius BorderWidth:(CGFloat)borderWidth BorderColor:(UIColor *)borderColor Image:(UIImage *)image ResultImageSize:(CGSize)resultImageSize CenterIconSize:(CGSize)centerIconSize;

/// 根据 CIImge 生成指定大小的 UIImage
+ (UIImage *)cn_imageWithCIImage:(CIImage *)image size:(CGSize)size;

/**
 *  传入图片,需要的大小,比例,得到压缩图片大小
 *
 *      @prama image 需要压缩的图片
 *      @prama size  压缩后图片的大小
 *      @prama scale 压缩的比例 0.0 - 1.0
 *
 *      @return 返回新的图片
 */
+ (JPEGImage *)needCompressImage:(UIImage *)image size:(CGSize )size scale:(CGFloat )scale;
+ (JPEGImage *)needCompressImageData:(NSData *)imageData size:(CGSize )size scale:(CGFloat )scale;

/**
 *  传入图片,获取中间部分,需要的大小,压缩比例
 *
 *      @prama image 需要压缩的图片
 *      @prama size  压缩后图片的大小
 *      @prama scale 压缩的比例 0.0 - 1.0
 *
 *      @return 返回新的图片
 */
+ (JPEGImage *)needCenterImage:(UIImage *)image size:(CGSize )size scale:(CGFloat )scale;


/**
 *  png图片转为jpeg(jpg)图片
 *
 *      @prama image 需要转为jpeg的png图片
 *
 *      @return 返回一张jpeg图片
 */
+ (JPEGImage *)jpegImageWithPNGImage:(PNGImage *)pngImage;
+ (JPEGImage *)jpegImageWithPNGData:(PNGData *)pngData;
+ (JPEGData *)jpegDataWithPNGData:(PNGData *)pngData;
+ (JPEGData *)jpegDataWithPNGImage:(PNGImage *)pngImage;

- (UIImage *) resizeImage:(UIImage *) img WithTop:(CGFloat) top WithLeft:(CGFloat) left WithBottom:(CGFloat) bottom WithRight:(CGFloat) right;

- (UIImage*) transformWidth:(CGFloat)width height:(CGFloat)height;


/**
 压缩图片,压缩 JPEG,PNG, 不含 GIF
 
 @param image 压缩前的图片
 @param imageType 指明图片类型
 @param size 期望压缩后的大小,单位:MB
 @return 压缩后的图片
 */
+ (UIImage *)cn_compressWithImage:(UIImage *)image imageType:(CNImageFormat)imageType specifySize:(CGFloat)size;

/**
 压缩图片,压缩 JPEG,PNG,GIF
 
 @param imageData 压缩前图片的data
 @param size 期望压缩后的大小,单位:MB
 @return 压缩后的图片
 */
+ (UIImage *)cn_compressWithImage:(NSData *)imageData specifySize:(CGFloat)size;


/*
 *  压缩图片方法(先压缩质量再压缩尺寸)
 */
-(NSData *)compressWithLengthLimit:(NSUInteger)maxLength;
/*
 *  压缩图片方法(压缩质量)
 */
-(NSData *)compressQualityWithLengthLimit:(NSInteger)maxLength;
/*
 *  压缩图片方法(压缩质量二分法)
 */
-(NSData *)compressMidQualityWithLengthLimit:(NSInteger)maxLength;
/*
 *  压缩图片方法(压缩尺寸)
 */
-(NSData *)compressBySizeWithLengthLimit:(NSUInteger)maxLength;

#pragma mark - 图片压缩
- (NSData *)resetSizeOfImageData:(UIImage *)sourceImage maxSize:(NSInteger)maxSize;
#pragma mark 调整图片分辨率/尺寸（等比例缩放）
- (UIImage *)newSizeImage:(CGSize)size image:(UIImage *)sourceImage;

+ (NSData *)scallGIFWithData:(NSData *)data scallSize:(CGSize)scallSize;

#pragma mark   -  图片

+(CGSize)imageSizeWithOriginalImage:(UIImage *)image;

/**  压缩图片*/
+ (UIImage *)imageWithOriginalImage:(UIImage *)image;

/**  压缩图片 压缩质量 0 -- 1*/
+ (UIImage *)imageWithOriginalImage:(UIImage *)image quality:(CGFloat)quality;

/**  压缩图片成Data*/
+ (NSData *)dataWithOriginalImage:(UIImage *)image;

/**  压缩图片 压缩质量 0 -- 1*/
+ (NSData *)imageDataWithOriginalImage:(UIImage *)image quality:(CGFloat)quality;

+ (NSData *)zipGIFWithData:(NSData *)data;

- (UIColor *)averageColor;

-(UIImage *)imageWaterImageWithImage:(UIImage *)image ImageLogo:(UIImage *)imageLogo title:(NSString *)string;
+(UIImage *)imageWaterImageWithImage:(UIImage *)image ImageLogo:(UIImage *)imageLogo title:(NSString *)string;



/// 图片压缩
/// @param size <#size description#>
- (UIImage *)cn_resizedImageWithSize:(CGSize)size;

///生成一张毛玻璃图片
- (UIImage*)blur;

//生成一张渐变图片
+ (UIImage *)makeGradientImageWithColors:(NSArray *)colors withSize:(CGSize)size cornerRadius:(CGFloat)radius locations:(CGFloat *)locations;
@end
